#include "../begonia.h"
#include "cmenu.h"
#include "cselect.h"
#include "cstory.h"

const char *menus[]={
    "GAME START",
    "BACKGROUND STORY",
    "QUIT"};
const int menun=3;

void cmenu::display(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glViewport(scx,scy,scw,sch);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0,scw,0,sch, -1.0, 1.0);
	glMatrixMode(GL_MODELVIEW);
    glColor3d(0.7,0.3,0.3);
    glBegin(GL_POLYGON);
        glVertex2d(0,0);
        glVertex2d(scw,0);
        glVertex2d(scw,sch);
        glVertex2d(0,sch);
    glEnd();
    glColor3d(1.0,1.0,1.0);
    drawstring(scw/2.0,sch/2.0+32.0,"DISTANT RECALL",0.5);
    for(int i=0;i<menun;i++)
    {
        drawstring(scw/2.0,sch/2.0-16.0*i,menus[i],0.5);
    }
    glColor3d(1.0,1.0,0.0);
    drawstring(scw/2.0,sch/2.0-16.0*menup,menus[menup],0.5);
    drawstring(scw/2.0-1.0,sch/2.0-16.0*menup,menus[menup],0.5);
    drawstring(scw,32.0,"MIMIC OF <SHOOT THE BULLET>",1.0);
    drawstring(scw,16.0,"& <DOUBLE SPOILER>",1.0);
    drawstring(scw,0.0,"SPECIAL THANKS TO ZUN",1.0);
    glutSwapBuffers();
}

void cmenu::key(unsigned char key, int x, int y)
{
    switch (key)
    {
        case 'a':
            ai=true;
            break;
        case 's':
            ai=false;
            break;

        case 'z': case 'Z':
            if(menup==0) screen=&select;
            else if(menup==1) screen=&story;
            else if(menup==2) exit(0);
        break;
    }
    glutPostRedisplay();
}

void cmenu::specialkey(int key, int x, int y)
{
    switch (key)
    {
        case GLUT_KEY_UP:
            menup=(menup+menun-1)%menun;
            break;
        case GLUT_KEY_DOWN:
            menup=(menup+1)%menun;
            break;
    }
    glutPostRedisplay();
}
